#include "user.h"

#define TAG "user"

TaskHandle_t Key_Task_Handle =                              NULL;
TaskHandle_t tcp_client_task_Handle =                       NULL;
TaskHandle_t OLED_task_Handle =                             NULL;
TaskHandle_t tcp_server_task_Handle =                       NULL;
TaskHandle_t tcp_time_synchronization_Task_Handle =         NULL;
TaskHandle_t WiFi_Init_Task_Handle =                        NULL;
TaskHandle_t UART_Task_Handle =                             NULL;



void Task_Init(void)
{
   
    IO_KET_LED_Init();
    I2C_Init();
    //WiFi_auto_Init();
    OLED_Init();
    OLED_Clear();
}


void Task_Create(void)
{
    u8 ff[] = "ESP32_APP_START" ;
   
    WiFi_EventGroupHandle = xEventGroupCreate();
    Oled_EventGroupHandle = xEventGroupCreate();
    Key_EventGroupHandle = xEventGroupCreate();
    Task_Init();
    OLED_ShowString(0,0,ff,16); 
    


    Time_synchronization_Queue_Handle = xQueueCreate(1,64);

    xTaskCreatePinnedToCore(
        KEY_Task,
        "KEY_Task",
        1024,
        NULL,
        0,
        &Key_Task_Handle,
        0
    );
    
    //  xTaskCreatePinnedToCore(
    //     tcp_server_task,
    //     "tcp_server_task",
    //     1024*5,
    //     NULL,
    //     11,
    //     &tcp_server_task_Handle,
    //     0
    // );
    
    xTaskCreatePinnedToCore(
        tcp_client_task,
        "tcp_client_task",
        1024*5,
        NULL,
        11,
        &tcp_client_task_Handle,
        0
    );

    xTaskCreatePinnedToCore(
        WiFi_Init_Task,
        "WiFi_Init_Task",
        1024*5,
        NULL,
        11,
        &WiFi_Init_Task_Handle,
        1
    ); 
    xTaskCreatePinnedToCore(
        OLED_task,
        "OLED_task",
        1024*5,
        NULL,
        1,
        &OLED_task_Handle,
        0
    );
    xTaskCreatePinnedToCore(
        time_synchronization_Task,
        "time_synchronization_Task",
        1024*5,
        NULL,
        1,
        &tcp_time_synchronization_Task_Handle,
        0
    );
    
    // xTaskCreatePinnedToCore(
    //     UART_Task,
    //     "UART_Task",
    //     1024*5,
    //     NULL,
    //     0,
    //     &UART_Task_Handle,
    //     0
    // );
}


